/*
 * Team Name: Team Sasquatch
 * Cody Sharff
 * Anthony Rios
 * Prince Kishore
 * Travis Drake
 */

package gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;

/**
 * This GUI allows the bidder to be able to view their bids on items.
 * 
 * @author Anthony Rios
 * 
 * @version 05/29/2012
 */
public class ViewBidsGUI extends Observable{
	
	private final JPanel my_item_panel;
	
	private List<String> my_item_list = new ArrayList<String>();
	
	private List<Integer> my_bids_list = new ArrayList<Integer>();
				
	private final JButton my_cancel_button = new JButton("Back");
		
	/**
	 * the constructor for this GUI.  Creates an observable panel.  To get the panel
	 * use the getPanel method. The parameter are the item/Id and bid amount.  Both will
	 * be diplayed in the GUI.
	 * 
	 * @required the_item_list != null
	 * @ensures the bids for item if any
	 */
	public ViewBidsGUI(List<String> the_item_list, List<Integer> the_bids_list) {
		my_item_panel = new JPanel();
		my_item_panel.setName("My Current Bids");
		my_item_panel.setLayout(new BorderLayout());
		my_cancel_button.addActionListener(new cancelButtonListener());
		my_item_list = the_item_list;
		my_bids_list = the_bids_list;
		layoutComponents();
	}
	
	/**
	 * layout all the buttons and text fields in the proper format by using
	 * an assortment of panels.
	 */
	public void layoutComponents() {
		final JPanel spring_layout = new JPanel();
		spring_layout.setLayout(new SpringLayout());
    	spring_layout.add(new JLabel("ITEM/ID"));
    	spring_layout.add(new JLabel("			"));
    	spring_layout.add(new JLabel("BID AMOUNT"));
        for (int i = 0; i < my_item_list.size(); i++) {
        	spring_layout.add(new JLabel(my_item_list.get(i).toString()));
        	spring_layout.add(new JLabel("				"));
        	spring_layout.add(new JLabel(my_bids_list.get(i).toString()));
        }
        SpringUtilities.makeCompactGrid(spring_layout,
                my_item_list.size() + 1, 3,        //rows, cols
                6, 6,        //initX, initY
                6, 6);       //xPad, yPad
        my_item_panel.add(spring_layout, BorderLayout.CENTER);
        JPanel south_panel = new JPanel(new FlowLayout());
        south_panel.add(my_cancel_button);
        my_item_panel.add(south_panel, BorderLayout.SOUTH);
	}

	public JPanel getPanel() {
		return my_item_panel;
	}
	
	/**
     * Action listeners for the submit and cancel button.
     * 
     * @author Anthony Rios
     * @version 05-28-12
     */
    protected class cancelButtonListener implements ActionListener
    {
    	
     /**
      *  when the back button is selected a string "BACK" is sent to the observer.
      */
      @Override
      public void actionPerformed(final ActionEvent the_event)
      {
    		  setChanged();
			  notifyObservers(AuctionViewGUI.BACK);
      }
    }
}
